package cn.tedu.micro.demo.rabbitmq.ampq;

import cn.tedu.micro.demo.rabbitmq.pojo.UserMsg;
import com.rabbitmq.client.Channel;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;

import java.io.IOException;

@Component
@Slf4j
public class DemoConsumer {
    @RabbitListener(queues = "demo-queue")
    public void consumer00(UserMsg userMsg, Message  message, Channel channel){
        log.info("消费者获得消息{}",userMsg);
        byte[] body = message.getBody();
        String message1 = new String(body);
        log.info("消费者解析消息对象body{}",message1);
        try {
            channel.basicAck(message.getMessageProperties().getDeliveryTag(),false);
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }
}
